new Vue({
    el: '#app',
    data() {
        return {
            form: {
                SQLSerialNumber: "P_base_page_info",
                PaginationNumber: 1,			//页数
                RowAmount: 10,			//每页数据条数
                Condition:'',
                ExtensionCondition:'',
            },
            total: 0,
            tableData: [],		//表格数据
        }
    },
    mounted() {
        this.getList(this.form)
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        Add() {
            window.location.href = './add.html?Open_ID=oC5yg5fCqG02aJ6CEShpHbXUXlys'
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getList(data) {//换页方法
            const that = this
            $.ajax({
                headers:requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Publish(row) {//发布
            const that = this;
            if (row.Absolute_Path) {
                window.open(`${BASE_URL4}/${row.Page_SerialNumber}.html`, '_blank');
            } else {
                this.$confirm('是否要发布该页面?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    $.ajax({
                        headers:requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSaveFiles`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({
                                FileName: row.Page_SerialNumber,
                                FileContent: row.File_String
                            })
                        },
                        success: function (res) {
                            if (res.Status == 'success') {
                                row.Absolute_Path = res.Path
                                that.Modify(row,'发布');
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                }).catch(() => { });
            }
        },
        Modify(obj,str) {
            const that = this;
            $.ajax({
                headers:requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalSave`,
                type: 'POST',
                data: {
                    Data: JSON.stringify({ Modify: { base_page_info: [obj] } })
                },
                success: function (res) {
                    if (res.Status === 'success') {
                        that.$message({
                            type: 'success',
                            message: str+'成功!'
                        });
                        that.getList(that.form);
                    } else {
                        that.$message.error(str+"失败，请稍后再试")
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            })
        },
        Edit(Page_SerialNumber) {
            sessionStorage.setItem("Page_SerialNumber", Page_SerialNumber)
            window.location.href = './edit.html?Page_SerialNumber=' + Page_SerialNumber+"&Open_ID=oC5yg5fCqG02aJ6CEShpHbXUXlys"
        },
        Remove(row) {
            const that = this
            this.$confirm('警告！此操作将删除该页面, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                row.Row_Status = '1';
                that.Modify(row,'删除');
            }).catch(() => { });
        },
        WeChat(row){
            const that = this
            this.$confirm('是否将该页面设置为小程序首页?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    headers:requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    type: 'POST',
                    data: { 
                        Data: "base_page_info" ,
                        Condition: "App_ID='1'"
                    },
                    success: function (data) {
                        data.forEach(item => {
                            item.App_ID = '';
                        });
                        let obj = deepClone(row);
                        obj.App_ID = '1'
                        // console.log({ Modify: { base_page_info: [...data,obj] } });
                        $.ajax({
                            headers:requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            type: 'POST',
                            data: {
                                Data: JSON.stringify({ Modify: { base_page_info: [...data,obj] } })
                            },
                            success: function (res) {
                                if (res.Status === 'success') {
                                    that.$message({
                                        type: 'success',
                                        message: '操作成功!'
                                    });
                                    that.getList(that.form);
                                } else {
                                    that.$message.error("操作失败，请稍后再试")
                                }
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
                    },
                    dataType: "json"
                });
            }).catch(() => { });
        }
    },
})